package ar.uade.fain.ai.tpo.view.comida;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.SwingUtilities;
import javax.swing.WindowConstants;

import ar.uade.fain.ai.tpo.Sistema;
import ar.uade.fain.ai.tpo.dto.ComidaDTO;

/**
 * This code was edited or generated using CloudGarden's Jigloo SWT/Swing GUI
 * Builder, which is free for non-commercial use. If Jigloo is being used
 * commercially (ie, by a corporation, company or business for any purpose
 * whatever) then you should purchase a license for each developer using Jigloo.
 * Please visit www.cloudgarden.com for details. Use of Jigloo implies
 * acceptance of these licensing terms. A COMMERCIAL LICENSE HAS NOT BEEN
 * PURCHASED FOR THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED LEGALLY FOR
 * ANY CORPORATE OR COMMERCIAL PURPOSE.
 */
public class AltaComida extends javax.swing.JFrame {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private JButton aceptar;
	private JLabel comidaLabel;
	private JTextField nombreField;
	private JTextField seccionField;
	private JLabel seccionLabel;
	private JTextField categoriaField;
	private JLabel categoriaLabel;
	private JTextField recetaText;
	private JLabel recetaLabel;

	/**
	 * Auto-generated main method to display this JFrame
	 */
	public static void main(String[] args) {
		SwingUtilities.invokeLater(new Runnable() {
			public void run() {
				AltaComida inst = new AltaComida();
				inst.setLocationRelativeTo(null);
				inst.setVisible(true);
			}
		});
	}

	public AltaComida() {
		super();
		initGUI();
	}

	private void initGUI() {
		try {
			setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
			getContentPane().setLayout(null);
			{
				aceptar = new JButton();
				getContentPane().add(aceptar);
				aceptar.setText("Aceptar");
				aceptar.setBounds(143, 266, 137, 23);
				aceptar.addActionListener(new ActionListener() {

					@Override
					public void actionPerformed(ActionEvent e) {
						if (!nombreField.getText().isEmpty()) {
							ComidaDTO comidaDTO = new ComidaDTO();
							comidaDTO.setNombre(nombreField.getText());
							comidaDTO.setIdCategoria(Long
									.parseLong(categoriaField.getText()));
							comidaDTO.setIdReceta(Long.parseLong(recetaText
									.getText()));
							comidaDTO.setIdSeccion(Long.parseLong(seccionField
									.getText()));
							Sistema.get().getComidaControlador()
									.altaComida(comidaDTO);
						}
					}
				});
			}
			{
				comidaLabel = new JLabel();
				getContentPane().add(comidaLabel);
				comidaLabel.setText("Nombre Comida:");
				comidaLabel.setBounds(31, 25, 104, 16);
			}
			{
				nombreField = new JTextField();
				getContentPane().add(nombreField);
				nombreField.setBounds(172, 22, 161, 19);
			}
			{
				categoriaLabel = new JLabel();
				getContentPane().add(categoriaLabel);
				categoriaLabel.setText("Categoria:");
				categoriaLabel.setBounds(31, 60, 54, 16);
			}
			{
				categoriaField = new JTextField();
				getContentPane().add(categoriaField);
				categoriaField.setBounds(172, 57, 161, 19);
			}
			{
				recetaLabel = new JLabel();
				getContentPane().add(recetaLabel);
				recetaLabel.setText("idReceta:");
				recetaLabel.setBounds(31, 108, 91, 16);
			}
			{
				recetaText = new JTextField();
				getContentPane().add(recetaText);
				recetaText.setBounds(172, 106, 161, 18);
			}
			{
				seccionLabel = new JLabel();
				getContentPane().add(seccionLabel);
				seccionLabel.setText("idSeccion:");
				seccionLabel.setBounds(31, 163, 104, 16);
			}
			{
				seccionField = new JTextField();
				getContentPane().add(seccionField);
				seccionField.setBounds(172, 162, 161, 19);
			}
			pack();
			this.setSize(410, 338);
		} catch (Exception e) {
			// add your error handling code here
			e.printStackTrace();
		}
	}

}
